﻿using System;
using System.ComponentModel;

namespace DateReminderApp
{
    [Serializable]
    public class Reminder : INotifyPropertyChanged
    {
        private string _title;
        private DateTime _reminderTime;
        private string _description;
        private bool _isCompleted;

        public Reminder()
        {
            _title = "新提醒";
            _description = "";
            _reminderTime = DateTime.Now.AddHours(1);
            _isCompleted = false;
        }

        public string Title
        {
            get => _title ?? string.Empty;
            set { _title = value; OnPropertyChanged(nameof(Title)); }
        }

        public DateTime ReminderTime
        {
            get => _reminderTime;
            set { _reminderTime = value; OnPropertyChanged(nameof(ReminderTime)); }
        }

        public string Description
        {
            get => _description ?? string.Empty;
            set { _description = value; OnPropertyChanged(nameof(Description)); }
        }

        public bool IsCompleted
        {
            get => _isCompleted;
            set { _isCompleted = value; OnPropertyChanged(nameof(IsCompleted)); }
        }

        public TimeSpan TimeUntilReminder => ReminderTime - DateTime.Now;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        public override string ToString()
        {
            return $"{Title} - {ReminderTime:yyyy-MM-dd HH:mm}";
        }
    }
}